var dataDetail = null;

;layui.define(function(e) {
    layui.use(['table','layer','form','laydate','util'], function(){
        var $ = layui.$
            ,layer = layui.layer
            ,form = layui.form
            ,table = layui.table
            ,laydate = layui.laydate;
        //展示已知数据
        table.render({
            elem: '#idTable'
            ,id: 'listReload'
            ,url: hostUrl+'/broke/rakeBack/brokerList'
            ,cellMinWidth: 180
            ,loading: true
            ,cols: [[ //标题栏、
            	{field: 'account', title: '手机号', minWidth: 130}
                ,{field: 'name', title: '经纪人姓名', minWidth: 110}
                ,{field: 'bname', title: '绑定企业'}
                ,{field: 'add_time', title: '创建时间', minWidth: 180,templet: function(d){
                	return layui.util.toDateString(d.add_time, 'yyyy-MM-dd HH:mm:ss');
                }}
                ,{field: 'gross_amount', title: '累积返佣金额(元)', minWidth: 110,templet: function(d){
                	if(d.gross_amount==''||d.gross_amount==null){
                		return 0;
                	}else{
                		return d.gross_amount;
                	}
                }}   
                ,{field: 'usable_amount', title: '可提现金额(元)', minWidth: 110,templet: function(d){
                	if(d.usable_amount==''||d.usable_amount==null){
                		return 0;
                	}else{
                		return d.usable_amount;
                	}
                }}    
                ,{field: 'tool',title: '操作',fixed: 'right', minWidth:100, align:'center', toolbar: '#barDemo'}
            ]]
            ,page: true //是否显示分页
        });
       
        form.on('select(selectStore)', function(data){
        	selectStore();
        });
        
        //监听工具条
        table.on('tool(listTable)', function(obj){
            var data = obj.data;
            if(obj.event === 'edit'){
            	dataDetail=data;
            	var detail=layer.open({
                    type: 2
                    ,id: (new Date()).valueOf()
                    ,title: '编辑'
                    ,content: hostUrl+'/broker/broker/edit.do'
                    ,area:  ['500px', '500px']
                    ,maxmin: true
                    ,end: function(){
                    	dataDetail=null;
                    }
                }); 
            	layer.full(detail); 
            }
        });
        
   
//        
//        $("#inputOptions").click(function () {
//		    return window.location.href=hostUrl+"/broke/rakeBack/dowExcel?accName="+$("#accName").val()+"&account="+$("#account").val();
//        })
        //表刷新方法
        var reloadTable = function () {
            table.reload("listReload", { //此处是上文提到的 初始化标识id
                where: {
                	startDate: $("#startDate").val(),
                	endDate: $("#endDate").val(),
                	account: $("#account").val()
                }
            });
        };
        $("#search-button").on("click",function () {
            reloadTable();
        })
    });
    
    //日期控件
    layui.use(['laydate'], function(){
        var laydate = layui.laydate;
      	//常规用法
        laydate.render({
          elem: '#startDate'
        });
        
        laydate.render({
          elem: '#endDate'
        });
    });
    
});